package com.share.demo.dao;

import com.share.demo.domain.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.Repository;

/**
 * caifan
 */
public interface UserRepository extends CrudRepository<User, Long>, Repository<User, Long> {

    User findUserById(Long id);

    Page<User> findAll(Pageable pageable);

    //void updateUser(User user);

    @Modifying
    @Query("update User u set u.age = ?2 where id = ?1")
    void updateUserAge(Long id, Integer age);

    /**
     * 先查询是否存在再删除，@Modifying @Query可以直接删除
     * @param id
     */
    void deleteUserById(Long id);
}
